class Solution:
    def missingNumber(self, nums) -> int:
        hadZero = False
        for i in range(len(nums)):
            if nums[i] == 0:
                nums[i] = len(nums) + 1
                hadZero = True
                break
        if not hadZero:
            return 0

        for i in nums:
            i = abs(i)
            if i == len(nums) + 1:
                continue
            nums[i - 1] = nums[i - 1] * (-1)
        for i in range(len(nums)):
            if i == len(nums) + 1:
                continue
            if nums[i] > 0:
                return i+1


if __name__ == '__main__':
    so = Solution()
    m = [9,6,4,2,3,5,7,0,1]
    r = so.missingNumber(m)
    print(r)
